namespace Mole
{
    using System;

    public static class AlertOnEvent
    {
        private static EventHandler<AlertOnEventArgs> _ErrorAlertOnEventHandler;
        private static readonly object _eventLock = new object();

        public static  event EventHandler<AlertOnEventArgs> ErrorAlertOnEventHandler
        {
            add
            {
                lock (_eventLock)
                {
                    _ErrorAlertOnEventHandler = (EventHandler<AlertOnEventArgs>) Delegate.Combine(_ErrorAlertOnEventHandler, value);
                }
            }
            remove
            {
                lock (_eventLock)
                {
                    _ErrorAlertOnEventHandler = (EventHandler<AlertOnEventArgs>) Delegate.Remove(_ErrorAlertOnEventHandler, value);
                }
            }
        }

        public static void OnAlertEvent(object sender, AlertOnEventArgs e)
        {
            EventHandler<AlertOnEventArgs> handler = null;
            lock (_eventLock)
            {
                handler = _ErrorAlertOnEventHandler;
                if (handler == null)
                {
                    return;
                }
            }
            handler(sender, e);
        }
    }
}

